<template>
  <div class="index-container">
    <div class="content">
      <el-form
        ref="form"
        class="demo-form-inline"
        :inline="true"
        :model="queryForm"
        @submit.native.prevent
      >
        <el-form-item>
          <el-select v-model="value1" placeholder="骑行区域">
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="value1" placeholder="工单类型">
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="value1" placeholder="状态报修">
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            end-placeholder="订单创建-结束"
            range-separator="至"
            start-placeholder="订单创建-开始"
            type="datetimerange"
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="queryForm.order"
            clearable
            placeholder="车牌号/维修人昵称/手机号"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            native-type="submit"
            type="primary"
            @click="handleQuery"
          >
            查询
          </el-button>
          <el-button icon="el-icon-delete" type="danger" @click="handlReset()">
            重置
          </el-button>
        </el-form-item>
      </el-form>
      <div class="right">
        <div>
          <el-button plain type="primary">批量完成</el-button>
        </div>
        <div>
          <el-button plain type="warning">批量指派</el-button>
        </div>
        <div>
          <el-button plain type="success">添加工单</el-button>
        </div>
      </div>
    </div>
    <!-- 表格体部分 -->
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :border="border"
      :data="list"
      style="width: 100%"
      @selection-change="setSelectRows"
    >
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column
        align="center"
        label="序号"
        show-overflow-tooltip
        width="55"
      >
        <!-- 序号内容的列 -->
        <template #default="{ $index }">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item, index) in finallyColumns"
        :key="index"
        align="center"
        :label="item.label"
        :sortable="item.sortable"
        :width="item.width"
      >
        <!-- 的列 -->
        <template #default="{ row }">
          <span>{{ row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        fixed="right"
        label="操作"
        show-overflow-tooltip
        width="300"
      >
        <template #default="{ row }">
          <el-button plain type="white" @click="handleEdit(row)">
            详情
          </el-button>
          <el-button plain type="warning" @click="handleEdit(row)">
            点击完成
          </el-button>
          <el-button plain type="success" @click="handleDelete(row)">
            点击指派
          </el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-image
          class="vab-data-empty"
          :src="require('@/assets/empty_images/data_empty.png')"
        />
      </template>
    </el-table>
    <!-- 这个是底部页面跳转内容 -->
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <!-- <table-edit ref="edit" /> -->
  </div>
</template>

<script>
  import { getList } from '@/api/table'
  // import TableEdit from './components/TableEdit'

  export default {
    name: 'Order',
    components: {
      // 需要外部的两个组件
      // TableEdit,
    },
    data() {
      return {
        options1: [
          { value: '选项1', label: '黄金糕' },
          { value: '选项2', label: '双皮奶' },
          { value: '选项3', label: '蚵仔煎' },
          { value: '选项4', label: '龙须面' },
          { value: '选项5', label: '北京烤鸭' },
        ],
        value1: '',
        isFullscreen: false,
        border: true,
        checkList: [
          '车牌号',
          '中控号',
          '工单类型',
          '原因',
          '接单人',
          '手机号',
          '区域',
          '报警时间',
          '插入次数',
          '接单时间',
          '工单进度',
          '完成时间',
          '报修状态',
        ],
        columns: [
          {
            label: '车牌号',
            width: 'auto',
            prop: 'order',
            sortable: true,
            disableCheck: true,
          },
          {
            label: '中控号',
            width: 'auto',
            prop: 'city',
            sortable: true,
          },
          {
            label: '工单类型',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '原因',
            width: 'auto',
            prop: 'phone',
            sortable: true,
          },
          {
            label: '接单人',
            width: '200',
            prop: 'number',
            sortable: true,
          },

          {
            label: '手机号',
            width: '300',
            prop: 'origin',
            sortable: true,
          },
          {
            label: '区域',
            width: '400',
            prop: 'flag',
            sortable: true,
          },
          {
            label: '报警时间',
            width: '300',
            prop: 'time',
            sortable: true,
          },
          {
            label: '插入次数',
            width: '100',
            // prop: '未填写',
            sortable: true,
          },
          {
            label: '接单时间',
            width: '300',
            // prop: '未填写',
            sortable: true,
          },
          {
            label: '工单进度',
            width: '200',
            // prop: '未填写',
            sortable: true,
          },
          {
            label: '完成时间',
            width: '300',
            // prop: '未填写',
            sortable: true,
          },
          {
            label: '报修状态',
            width: '200',
            // prop: '未填写',
            sortable: true,
          },
        ],
        list: [],
        imageList: [],
        // 加载状态
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        // 初始状态下跳转页面的数据
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
      }
    },
    computed: {
      dragOptions() {
        return {
          animation: 600,
          group: 'description',
        }
      },
      finallyColumns() {
        return this.columns.filter((item) =>
          this.checkList.includes(item.label)
        )
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      // handleAdd() {
      //   this.$refs['edit'].showEdit()
      // },
      // handleEdit(row) {
      //   this.$refs['edit'].showEdit(row)
      // },
      // 删除操作,
      // handleDelete(row) {
      //   if (row.id) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       const { msg } = await doDelete({ ids: row.id })
      //       this.$baseMessage(msg, 'success', false, 'vab-hey-message-success')
      //       await this.fetchData()
      //     })
      //   } else {
      //     if (this.selectRows.length > 0) {
      //       const ids = this.selectRows.map((item) => item.id).join()
      //       this.$baseConfirm('你确定要删除选中项吗', null, async () => {
      //         const { msg } = await doDelete({ ids: ids })
      //         this.$baseMessage(
      //           msg,
      //           'success',
      //           false,
      //           'vab-hey-message-success'
      //         )
      //         await this.fetchData()
      //       })
      //     } else {
      //       this.$baseMessage(
      //         '未选中任何行',
      //         'error',
      //         false,
      //         'vab-hey-message-error'
      //       )
      //     }
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleReset() {},
      handleQuery() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        const { list, total } = data
        this.list = list
        const imageList = []
        list.forEach((item) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
        this.total = total
        this.listLoading = false
      },
    },
  }
</script>

//
<style lang="scss" scoped>
  .custom-table-container {
    ::v-deep {
      i {
        cursor: pointer;
      }
    }
    .stripe-panel,
    .border-panel {
      margin: 0 10px $base-margin 10px !important;
    }
  }
</style>
//
<style lang="scss">
  .custom-table-checkbox {
    [class*='ri'] {
      vertical-align: -2.5px;
      cursor: pointer;
    }

    .el-checkbox {
      margin: 5px 0 5px 8px;
    }
  }
</style>
<style>
  .vab-query-form-left-panel {
    border: 2px solid red !important;
  }
  .vab-query-form-right-panel {
    border: 1px solid yellow;
  }
</style>
<style scoped>
  .content {
    display: flex;
  }
  .el-form {
    width: 80%;
  }
  .right {
    display: flex;
  }
</style>
